import java.util.ArrayList;
import java.util.List;

public class Solution71 {
    public String simplifyPath(String path) {
        //return Paths.get(path).normalize().toString();
        List<String> d = new ArrayList<>();
        for (int i = 0; i < path.length(); i++) {
            if (path.charAt(i) == '/') {
                if (i + 1 == path.length()) {
                    break;
                }
                if (path.charAt(i + 1) == '/') {
                    continue;
                }
                StringBuilder sb = new StringBuilder("/");
                for (i++; i < path.length(); i++) {
                    char c = path.charAt(i);
                    if (c == '/') {
                        break;
                    }
                    sb.append(c);
                }
                i--;
                String s = sb.toString();
                if (s.equals("/.")) {
                    continue;
                }
                if (s.equals("/..")) {
                    if (d.size() != 0) {
                        d.remove(d.size() - 1);
                    }
                } else {
                    d.add(s);
                }
            }
        }
        StringBuilder res = new StringBuilder();
        if (d.size() == 0) {
            return "/";
        } else {
            for (String s : d) {
                res.append(s);
            }
        }
        return res.toString();
    }
}
